const connect = require("../sql")

//获取的是所有的学生信息
async function queryall(req,res){
    const sql = "select * from student"
    const result = await connect(sql,[])
    if(result.length){
        res.send({code:200,msg:result})
    }else{
        res.send({code:302,msg:"获取所有学生信息失败"})
    }
}
//根据学生ID获取学生的信息
async function queryone(req,res){
    const {id} = req.query;
    const sql = "select * from student,clazz where student.clazzid = clazz.cid and student.sid = ?"
    const result = await connect(sql,[id])
    if(result.length){
        res.send({code:200,msg:result[0]})
    }else{
        res.send({code:403,msg:"当前学生信息不存在"})
    }
}

//根据班级ID获取学生信息
async function querystudentbyclazzid(req,res){
    const {clazzid} = req.query;
    const sql = "select * from Student where clazzid =?"
    const result = await connect(sql,[clazzid])
    if(result.length){
        res.send({code:200,msg:result})
    }else{
        res.send({code:404,msg:'当前班级ID不存在'})
    }
}
module.exports = {
    queryall,queryone,querystudentbyclazzid
}